import factory.GUIFactory;
import service.Button;
import service.CheckBox;
import service.TextField;

/**
 * 应用程序类 - 使用抽象工厂
 */
public class Application {
    private Button button;
    private TextField textField;
    private CheckBox checkBox;
    private GUIFactory factory;
    
    public Application(GUIFactory factory) {
        this.factory = factory;
    }
    
    /**
     * 创建UI组件
     */
    public void createUI() {
        System.out.println("使用 " + factory.getClass().getSimpleName() + " 创建UI组件");
        System.out.println("对话框样式: " + factory.getDialogStyle());
        System.out.println();
        
        button = factory.createButton();
        textField = factory.createTextField();
        checkBox = factory.createCheckBox();
    }
    
    /**
     * 渲染UI
     */
    public void render() {
        System.out.println("=== 渲染UI组件 ===");
        button.render();
        textField.render();
        checkBox.render();
        System.out.println();
    }
    
    /**
     * 与UI交互
     */
    public void interact() {
        System.out.println("=== 与UI交互 ===");
        button.setText("点击我");
        button.onClick();
        
        textField.setPlaceholder("请输入文本...");
        textField.setText("Hello World");
        
        checkBox.setLabel("我同意条款");
        checkBox.setChecked(true);
        
        System.out.println();
    }
    
    /**
     * 重新渲染查看变化
     */
    public void renderAfterInteraction() {
        System.out.println("=== 交互后的UI ===");
        button.render();
        textField.render();
        checkBox.render();
        System.out.println();
    }
}
